package com.huluobo.a2112mvvmdouyindemo.home;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm_base.bean.HomeTabBannerBeanResult;
import com.huluobo.mvvm_base.bean.HomeVideoBeanResult;
import com.huluobo.mvvm_base.model.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by LC on 2024/3/25.
 */
public class HomeRepo extends BaseRepo {

    public void getHomeVideoList(
            int currentPage,
            int pageSize,
            MutableLiveData<HomeVideoBeanResult> success,
            MutableLiveData<String> failed) {
        apiService.getHomeVideo(currentPage, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<HomeVideoBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(HomeVideoBeanResult homeVideoBeanResult) {
                        success.setValue(homeVideoBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getHomeBanner(MutableLiveData<HomeTabBannerBeanResult> success, MutableLiveData<String> failed) {
        apiService.getHomeBanner()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<HomeTabBannerBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(HomeTabBannerBeanResult homeTabBannerBeanResult) {
                        success.setValue(homeTabBannerBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
